<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitealbum
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: Controller.php 2011-08-026 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
class Sitealbum_Widget_FriendsPhotosController extends Engine_Content_Widget_Abstract {

  protected $_childCount;

  public function indexAction() {
    $viewer = Engine_Api::_()->user()->getViewer();
    $viewer_id = $viewer->getIdentity();
    // Check if friendship is allowed in the network
    $eligible = (int) Engine_Api::_()->getApi('settings', 'core')->getSetting('user.friends.eligible', 2);
    $photoType = Engine_Api::_()->getApi('settings', 'core')->getSetting('sitealbum.phototype', null);
		$friendPhotoView = Engine_Api::_()->getApi('settings', 'core')->getSetting('sitealbum.coreview', null);

    if (!$eligible || empty($viewer_id) || empty($photoType) || empty($friendPhotoView)) {
      return $this->setNoRender();
    }
    // get viewer friends
    $friends = $viewer->membership()->getMembers();
    // Get stuff
    $ids = array();
    foreach ($friends as $friend) {
      $ids[] = $friend->user_id;
    }
    if (empty($ids) || empty($photoType)) {
      return $this->setNoRender();
    }
    
    $this->view->friendsPhoto = $friendsPhoto = Engine_Api::_()->sitealbum()->getFriendsPhotos($ids, $this->_getParam('itemCountPhoto', 2));
    $count = $friendsPhoto->count();
    if ($count <= 0) {
      return $this->setNoRender();
    }

    $this->view->showLightBox = Engine_Api::_()->sitealbum()->showLightBoxPhoto();
    $this->view->count = $count;
    $this->view->is_ajax = $is_ajax = $this->_getParam('isajax', '');
  }

}
?>